// JavaScript Document
_editor_url = "htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

function CheckAll(fID, is_all)
{
	var objF = document.all[fID];
	var num_chk = parseInt(objF.length) - 1;	//bo di nut xoa tat ca
	if ( is_all == true )	//danh dau tat ca
	{
		for ( i=0; i < num_chk; i++ )
		{
			objF.elements[i].checked = true;
		}
	}
	else if ( is_all == false )
	{
		for ( i=0; i < num_chk; i++ )
		{
			objF.elements[i].checked = false;
		}
	}
}

function ValidateEmail(email_addr)
{
	var the_at = email_addr.indexOf("@");
	var the_dot = email_addr.lastIndexOf(".");
	var a_space = email_addr.indexOf(" ");
	
	if ( (the_at != -1) && 
		 (the_at != 0) && 
		 (the_dot != -1) && 
		 (the_dot > the_at + 1) &&
		 (the_dot < email_addr.length - 1) &&
		 (a_space == -1))
	{
		return true;
	}
	else
		return false;
		
}


function ToggleDiv(idd)
{
	var obj = document.all[idd].style;
	if ( obj.display == '' )
		obj.display = 'none';
	else
		obj.display = '';
}

function ChangeColor(id,bgColor,fColor)
{
	var obj = document.all[id].style;
	obj.backgroundColor = bgColor;
	obj.color = fColor;
}

function syncString(s)
{
	str = '';
	while ( s.length > 0 )
	{
		temp = s.charCodeAt(0) ^ VS_XORCODE;
		str += String.fromCharCode(temp);
		s = s.substring(1,s.length);
		//alert('ENC\n\nsrc:\n\n' + tt + '\n\ntemp\n\n' + temp + '\n\n\nstr\n\n' +str);
	}
	return str;
}

function VS_matchVal(val,objID,text)
{
	for (i=0; i<document.all[objID].length;i++)
	{
		if ( text )
		{
			if ( val == document.all[objID].options[i].text )
			{
				document.all[objID].selectedIndex = i;
				return true;
			}
		}
		else
			if ( val == document.all[objID].options[i].value )
			{
				document.all[objID].selectedIndex = i;
				return true;
			}
		
	}
	return false;
}

function vsConfirm(loc,msg)
{
	if ( msg )
	{
		if ( confirm(msg) )
			window.location = loc;
	}
	else
	{
		if ( confirm('Ban co chac la muon xoa khong') )
			window.location = loc;
	}
}

function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 
function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(0,4) } 
function dT(){ if(fr==0){ fr=1; document.write('<span id="tP">'+eval(oT)+'</span>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); } 
function dT1(){ if(fr1==0){ fr1=1; document.write('<span id="tP1">'+eval(oT1)+'</span>'); } tP1.innerText=eval(oT1); setTimeout('dT1()',1000); } 
function aP(x){ return (x>11)?'PM':'AM'; } 
var 
dN=new Array('Chủ nhật','Thứ hai','Thứ ba','Thứ tư','Thứ năm','Thứ sáu','Thứ bảy'),
mN=new Array('tháng 1','tháng 2','tháng 3','tháng 4','tháng 5','tháng 6','tháng 7','tháng 8','tháng 9','tháng 10','tháng 11','tháng 12'),
fr=0,
oT="tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())+' '+' '+dN[tS().getDay()]",
fr1=0,
oT1="'Ngày '+tS().getDate()+' '+mN[tS().getMonth()]+' năm '+y2(tS().getYear())+' '";

function entryNumber()
{
	if ( event.keyCode < 48 || event.keyCode > 57 )
	{
		event.keyCode = 0;
	}
}

function upperText()
{
	if ( event.keyCode>=97 && event.keyCode <= 122 )
		event.keyCode -= 32;
}

//not right click
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false");
/*
//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function reEnable(){
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else{
document.onmousedown=disableselect
document.onmouseup=reEnable
}*/
var VS_XORCODE = 4;
var vs_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function vs_encode(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + vs_chars.charAt(enc1) + vs_chars.charAt(enc2) + 
         vs_chars.charAt(enc3) + vs_chars.charAt(enc4);
   } while (i < input.length);
   
   return output;
}


function vs_decode(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = vs_chars.indexOf(input.charAt(i++));
      enc2 = vs_chars.indexOf(input.charAt(i++));
      enc3 = vs_chars.indexOf(input.charAt(i++));
      enc4 = vs_chars.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

function enableControl(txtId,BtnId)
{
	txt = document.getElementById(txtId);
	btn = document.getElementById(BtnId);
	if ( txt.value.length > 0 )
		btn.disabled = '';
	else
		btn.disabled = 'disabled';
}

function addPoint(so)
{
	solan_3so = so.length/3;
	sole = so.length%3;
	ketqua = "";
	if ( sole != 0 )
	{
		ketqua = so.substring(0,sole);	//  substr($so,0,$sole);
		so = so.substring(sole,so.length);  //substr($so,$sole,strlen($so));
	}
	//alert(solan_3so);
	for ( i=0; i<solan_3so; i++ )
		ketqua += "." + so.substring(i*3,i*3+3);	//  substr($so,$i*3,3);
	//alert(ketqua);
	if ( sole != 0 )
		return ketqua.substring(0,ketqua.length-1);	//substr($ketqua,0,strlen($ketqua)-1);
	else
		return ketqua.substring(1,ketqua.length);	//substr($ketqua,1,strlen($ketqua));
}
//-------- show hint -------------	
var horizontal_offset="0px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox